<cfcomponent extends="AbsDAO" output="false">

	<cffunction name="create" access="public" returntype="Numeric" output="false">
		<cfargument name="blog" type="it.millemultimedia.easyBlog.model.Blog" required="true" />	
		<cfset var qry = "" />	
		<cfset var id = 0 />
		
		<cftransaction>
		
			<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
				INSERT INTO Blog
				(
					title,description,tagline,skin
				
				)
				VALUES
				(
					<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.blog.gettitle()#" null="false" />,
				<cfqueryparam cfsqltype="CF_SQL_LONGVARCHAR" value="#arguments.blog.getdescription()#" null="false" />,
				<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.blog.gettagline()#" null="false" />
				)
			</cfquery>
			
			<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
			SELECT MAX(idblog) AS id
			FROM Blog
			</cfquery>
			
			<cfset id = qry.id />
		
		</cftransaction>

		<cfreturn id />
	</cffunction>
	
	<cffunction name="read" access="public" returntype="Query" output="false">
		<cfargument name="blog" type="it.millemultimedia.easyBlog.model.Blog" required="true" />
		<cfset var qry="" />
		
		<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
			SELECT idblog,title,description,tagline,link
					
			FROM Blog
			WHERE idblog = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.blog.getidBlog()#" null="false" />
		</cfquery>
		
		<cfreturn qry />
	</cffunction>
	
	<cffunction name="update" access="public" returntype="void" output="false">
		<cfargument name="blog" type="it.millemultimedia.easyBlog.model.Blog" required="true" />
		
		<cfset var qry="" />

		<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
			UPDATE Blog
			SET title = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.blog.gettitle()#" null="false" />,
				description = <cfqueryparam cfsqltype="CF_SQL_LONGVARCHAR" value="#arguments.blog.getdescription()#" null="false" />,
				tagline = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.blog.gettagline()#" null="false" />,
				link = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.blog.getLink()#" null="false" />
			WHERE idblog = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.blog.getidBlog()#" null="false" />
		</cfquery>

	</cffunction>
	
	<cffunction name="delete" access="public" returntype="void" output="false">
		<cfargument name="blog" type="it.millemultimedia.easyBlog.model.Blog" required="true" />
		
		<cfset var qry="" />

		<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
			DELETE FROM Blog
			WHERE idblog = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.blog.getidBlog()#" null="false" />
		</cfquery>
	</cffunction>
	
	
	<cffunction name="list" access="public" returntype="Query" output="false">
		<cfargument name="blog" type="it.millemultimedia.easyBlog.model.Blog" required="true" />
		
		<cfset var qry="" />

		<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
			SELECT * 
			FROM Blog
			WHERE idBlog is NOT NULL 
			<cfif !isNull( arguments.blog.getidBlog() ) >
			AND  idBlog = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.blog.getidBlog()#" null="false" />
			</cfif>
			
				
			<cfif !isNull( arguments.blog.gettitle() ) >
			AND  title = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.blog.gettitle()#" null="false" />
			</cfif>
			
				
			<cfif !isNull( arguments.blog.getdescription() ) >
			AND  description = <cfqueryparam cfsqltype="CF_SQL_LONGVARCHAR" value="#arguments.blog.getdescription()#" null="false" />
			</cfif>
			
				
			<cfif !isNull( arguments.blog.gettagline() ) >
			AND  tagline = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.blog.gettagline()#" null="false" />
			</cfif>
			
		</cfquery>
		
		<cfreturn qry/>
	</cffunction>

</cfcomponent>
